<!-- HTML header for doxygen 1.8.9.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>ROSS: core/avl_tree.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <a href="https://github.com/ROSS-org/ROSS">
   <div id="projectname">ROSS
   </div>
   </a>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_af18cf245e3394ab3b436135935cfd6e.html">core</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">avl_tree.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="avl__tree_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="ross_8h.html">ross.h</a>&gt;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;</div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/* Copied and modified from http://pine.cs.yale.edu/pinewiki/C/AvlTree google cache */</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">/* implementation of an AVL tree with explicit heights */</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;</div>
<div class="line"><a name="l00007"></a><span class="lineno"><a class="line" href="structavlNode.html">    7</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structavlNode.html">avlNode</a> {</div>
<div class="line"><a name="l00008"></a><span class="lineno"><a class="line" href="structavlNode.html#ab6da3779d5790df42d5f8aada2531a18">    8</a></span>&#160;  <span class="keyword">struct </span><a class="code" href="structavlNode.html">avlNode</a> *<a class="code" href="structavlNode.html#ab6da3779d5790df42d5f8aada2531a18">child</a>[2];    <span class="comment">/* left and right */</span></div>
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">    9</a></span>&#160;  <a class="code" href="structtw__event.html">tw_event</a> *<a class="code" href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">key</a>;</div>
<div class="line"><a name="l00010"></a><span class="lineno"><a class="line" href="structavlNode.html#a07c7d2f5149f11307f020cd468a18406">   10</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="structavlNode.html#a07c7d2f5149f11307f020cd468a18406">height</a>;</div>
<div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="structavlNode.html#a896c587e048855c3650926e6348b45e4">   11</a></span>&#160;  <span class="keyword">struct </span><a class="code" href="structavlNode.html">avlNode</a> *<a class="code" href="structavlNode.html#a896c587e048855c3650926e6348b45e4">next</a>;        <span class="comment">/* for ROSS weird linked-list memory */</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;};</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment">/* empty avl tree is just a null pointer */</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div>
<div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="avl__tree_8h.html#ace3584edf551195542027d44853ac68e">   16</a></span>&#160;<span class="preprocessor">#define AVL_EMPTY (0)</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment">/* free a tree */</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="keywordtype">void</span> <a class="code" href="avl__tree_8h.html#ab4e70a7b81f6dba8943d502b4527ae40">avlDestroy</a>(<a class="code" href="structavlNode.html">AvlTree</a> t);</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment">/* return the height of a tree */</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="keywordtype">int</span> <a class="code" href="avl__tree_8h.html#ad240d5f5dbe910d958769e3778b7215a">avlGetHeight</a>(<a class="code" href="structavlNode.html">AvlTree</a> t);</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment">/* return nonzero if key is present in tree */</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keywordtype">int</span> <a class="code" href="avl__tree_8h.html#a4dc2cbb6184fa259e0fe3c1032acc1fb">avlSearch</a>(<a class="code" href="structavlNode.html">AvlTree</a> t, <a class="code" href="structtw__event.html">tw_event</a> *<a class="code" href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">key</a>);</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="comment">/* insert a new element into a tree */</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="comment">/* note *t is actual tree */</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="keywordtype">void</span> <a class="code" href="avl__tree_8h.html#a8bb2b5a6430ff1464d6065e5cd136a43">avlInsert</a>(<a class="code" href="structavlNode.html">AvlTree</a> *t, <a class="code" href="structtw__event.html">tw_event</a> *<a class="code" href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">key</a>);</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="comment">/* run sanity checks on tree (for debugging) */</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment">/* assert will fail if heights are wrong */</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="keywordtype">void</span> <a class="code" href="avl__tree_8h.html#a74e9487f454a7eb90f06390f606bff8d">avlSanityCheck</a>(<a class="code" href="structavlNode.html">AvlTree</a> t);</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="comment">/* print all keys of the tree in order */</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="keywordtype">void</span> <a class="code" href="avl__tree_8h.html#a0a442b029873a977e5c3369f8bf84177">avlPrintKeys</a>(<a class="code" href="structavlNode.html">AvlTree</a> t);</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="comment">/* delete and return minimum value in a tree */</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<a class="code" href="structtw__event.html">tw_event</a> * <a class="code" href="avl__tree_8h.html#a6a4f850cb0ae353f688d2f9953a93d5f">avlDeleteMin</a>(<a class="code" href="structavlNode.html">AvlTree</a> *t);</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<a class="code" href="structtw__event.html">tw_event</a> * <a class="code" href="avl__tree_8h.html#a0bf2fa317ba41b17cf40a029d0121eae">avlDelete</a>(<a class="code" href="structavlNode.html">AvlTree</a> *t, <a class="code" href="structtw__event.html">tw_event</a> *<a class="code" href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">key</a>);</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<a class="code" href="structavlNode.html">AvlTree</a> <a class="code" href="avl__tree_8h.html#aa54b2f5f340b60161c61d5c169ee8784">avl_alloc</a>(<span class="keywordtype">void</span>);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="keywordtype">void</span> <a class="code" href="avl__tree_8h.html#acf331e186c8087aff88ee1f8348a3e25">avl_free</a>(<a class="code" href="structavlNode.html">AvlTree</a> t);</div>
<div class="ttc" id="avl__tree_8h_html_a0bf2fa317ba41b17cf40a029d0121eae"><div class="ttname"><a href="avl__tree_8h.html#a0bf2fa317ba41b17cf40a029d0121eae">avlDelete</a></div><div class="ttdeci">tw_event * avlDelete(AvlTree *t, tw_event *key)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00251">avl_tree.c:251</a></div></div>
<div class="ttc" id="avl__tree_8h_html_a0a442b029873a977e5c3369f8bf84177"><div class="ttname"><a href="avl__tree_8h.html#a0a442b029873a977e5c3369f8bf84177">avlPrintKeys</a></div><div class="ttdeci">void avlPrintKeys(AvlTree t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00214">avl_tree.c:214</a></div></div>
<div class="ttc" id="structavlNode_html_af4c4fa522fb43459ef776ac2d547ea92"><div class="ttname"><a href="structavlNode.html#af4c4fa522fb43459ef776ac2d547ea92">avlNode::key</a></div><div class="ttdeci">tw_event * key</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8h_source.html#l00009">avl_tree.h:9</a></div></div>
<div class="ttc" id="avl__tree_8h_html_a4dc2cbb6184fa259e0fe3c1032acc1fb"><div class="ttname"><a href="avl__tree_8h.html#a4dc2cbb6184fa259e0fe3c1032acc1fb">avlSearch</a></div><div class="ttdeci">int avlSearch(AvlTree t, tw_event *key)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00040">avl_tree.c:40</a></div></div>
<div class="ttc" id="structtw__event_html"><div class="ttname"><a href="structtw__event.html">tw_event</a></div><div class="ttdoc">Event Stucture. </div><div class="ttdef"><b>Definition:</b> <a href="ross-types_8h_source.html#l00250">ross-types.h:250</a></div></div>
<div class="ttc" id="avl__tree_8h_html_ad240d5f5dbe910d958769e3778b7215a"><div class="ttname"><a href="avl__tree_8h.html#ad240d5f5dbe910d958769e3778b7215a">avlGetHeight</a></div><div class="ttdeci">int avlGetHeight(AvlTree t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00028">avl_tree.c:28</a></div></div>
<div class="ttc" id="avl__tree_8h_html_a6a4f850cb0ae353f688d2f9953a93d5f"><div class="ttname"><a href="avl__tree_8h.html#a6a4f850cb0ae353f688d2f9953a93d5f">avlDeleteMin</a></div><div class="ttdeci">tw_event * avlDeleteMin(AvlTree *t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00226">avl_tree.c:226</a></div></div>
<div class="ttc" id="ross_8h_html"><div class="ttname"><a href="ross_8h.html">ross.h</a></div></div>
<div class="ttc" id="structavlNode_html_a896c587e048855c3650926e6348b45e4"><div class="ttname"><a href="structavlNode.html#a896c587e048855c3650926e6348b45e4">avlNode::next</a></div><div class="ttdeci">struct avlNode * next</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8h_source.html#l00011">avl_tree.h:11</a></div></div>
<div class="ttc" id="avl__tree_8h_html_aa54b2f5f340b60161c61d5c169ee8784"><div class="ttname"><a href="avl__tree_8h.html#aa54b2f5f340b60161c61d5c169ee8784">avl_alloc</a></div><div class="ttdeci">AvlTree avl_alloc(void)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00300">avl_tree.c:300</a></div></div>
<div class="ttc" id="avl__tree_8h_html_ab4e70a7b81f6dba8943d502b4527ae40"><div class="ttname"><a href="avl__tree_8h.html#ab4e70a7b81f6dba8943d502b4527ae40">avlDestroy</a></div><div class="ttdeci">void avlDestroy(AvlTree t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00015">avl_tree.c:15</a></div></div>
<div class="ttc" id="avl__tree_8h_html_a74e9487f454a7eb90f06390f606bff8d"><div class="ttname"><a href="avl__tree_8h.html#a74e9487f454a7eb90f06390f606bff8d">avlSanityCheck</a></div><div class="ttdeci">void avlSanityCheck(AvlTree t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00072">avl_tree.c:72</a></div></div>
<div class="ttc" id="structavlNode_html_a07c7d2f5149f11307f020cd468a18406"><div class="ttname"><a href="structavlNode.html#a07c7d2f5149f11307f020cd468a18406">avlNode::height</a></div><div class="ttdeci">int height</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8h_source.html#l00010">avl_tree.h:10</a></div></div>
<div class="ttc" id="structavlNode_html"><div class="ttname"><a href="structavlNode.html">avlNode</a></div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8h_source.html#l00007">avl_tree.h:7</a></div></div>
<div class="ttc" id="structavlNode_html_ab6da3779d5790df42d5f8aada2531a18"><div class="ttname"><a href="structavlNode.html#ab6da3779d5790df42d5f8aada2531a18">avlNode::child</a></div><div class="ttdeci">struct avlNode * child[2]</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8h_source.html#l00008">avl_tree.h:8</a></div></div>
<div class="ttc" id="avl__tree_8h_html_a8bb2b5a6430ff1464d6065e5cd136a43"><div class="ttname"><a href="avl__tree_8h.html#a8bb2b5a6430ff1464d6065e5cd136a43">avlInsert</a></div><div class="ttdeci">void avlInsert(AvlTree *t, tw_event *key)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00163">avl_tree.c:163</a></div></div>
<div class="ttc" id="avl__tree_8h_html_acf331e186c8087aff88ee1f8348a3e25"><div class="ttname"><a href="avl__tree_8h.html#acf331e186c8087aff88ee1f8348a3e25">avl_free</a></div><div class="ttdeci">void avl_free(AvlTree t)</div><div class="ttdef"><b>Definition:</b> <a href="avl__tree_8c_source.html#l00316">avl_tree.c:316</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
